package cj.primariaiquest.dao;

import java.util.List;

import cj.primariaiquest.dao.exceptions.DaoException;
import cj.primariaiquest.model.Ticket;

/**
 * Utility class used to perform CRUD database operations for ticket
 * 
 * @author parvu georgian
 * 
 */
public class TicketEntityManager extends BaseEntityManager<Ticket> {

    public TicketEntityManager() {
	super();
    }

    /**
     * Stores a ticket to database
     * 
     * @param ticket
     *            Ticket to be stored
     * @throws DaoException
     */
    public synchronized void persist(final Ticket ticket) throws DaoException {
	try {
	    super.persist(ticket);
	} catch (Exception e) {
	    throw new DaoException(e);
	}
    }

    /**
     * Returns a List< Ticket > off all tickets from database.
     * 
     * @return List< Ticket >
     * @throws DaoException
     */
    public synchronized List<Ticket> getAllTickets() throws DaoException {
	try {
	    return super.getAllObjects(Ticket.class);
	} catch (Exception e) {
	    throw new DaoException(e);
	}
    }

    /**
     * Deletes the provided ticket from database.
     * 
     * @param ticket
     *            Ticket to be deleted
     * @throws DaoException
     */
    public synchronized void deleteTicket(final Ticket ticket)
	    throws DaoException {
	try {
	    super.deleteObject(ticket);
	} catch (Exception e) {
	    throw new DaoException(e);
	}
    }

    /**
     * Deletes all tickets from database
     * 
     * @throws DaoException
     */
    public synchronized void deleteAllTickets() throws DaoException {
	try {
	    super.deleteAllObjects(Ticket.class);
	} catch (Exception e) {
	    throw new DaoException(e);
	}
    }

}
